/**
 * 给一个棋盘，初始有黑有白，要求重复无数次以下操作：
 * 将当前局面下所有白子中，只有1个黑子邻居的白子挑出来
 * 将这些白子染成黑色
 * 
 * 直接用广搜即可
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;
using vi = vector<int>;
using pii = pair<int, int>;

template<> struct std::hash<pii>{
    std::size_t operator () (const pii & p) const{
        static const std::size_t SEED = (unsigned)time(nullptr);
        std::size_t ans = SEED;
        ans = ans * 13313 + p.first;
        ans = ans * 13313 + p.second;
        return ans;
    }
};

template<> struct std::equal_to<pii>{
    bool operator () (const pii & a, const pii & b) const {
        return a.first == b.first and a.second == b.second;
    }
};

std::unordered_set<pii> Black;
std::unordered_set<pii> Candi;
vector<vi> Board;

const array<pii, 4> DC {
    pii{-1, 0}, 
    pii{0, 1}, 
    pii{1, 0},
    pii{0, -1}
};

int H, W;

void work(){
    cin >> H >> W;
    Board.assign(H, vi(W, 0));
    for(int i=0;i<H;++i){
        string s; cin >> s;
        for(int j=0;j<W;++j){
            if('.' == s[j]) continue;

            Black.insert(pii{i, j});
            for(const auto & p : DC){
                auto nx = i + p.first;
                auto ny = j + p.second;

                if(0 <= nx and nx < H and 0 <= ny and ny < W){
                    auto it = Black.find(pii{nx, ny});
                    if(it == Black.end()){
                        if(1 == (Board[nx][ny] += 1)){
                            Candi.insert(pii{nx, ny});
                        }else{
                            auto jt = Candi.find(pii{nx, ny});
                            if(jt != Candi.end()) Candi.erase(jt);
                        }
                    }
                }
            }
        }
    }

    while(1){        
        std::unordered_set<pii> tmp;
        for(const auto & p : Candi){
            auto _ = Black.insert(p);
            // assert(_.second);

            for(const auto & pp : DC){
                auto nx = p.first + pp.first;
                auto ny = p.second + pp.second;
                if(0 <= nx and nx < H and 0 <= ny and ny < W){
                    auto it = Black.find(pii{nx, ny});
                    if(it == Black.end()){
                        if(1 == (Board[nx][ny] += 1)){
                            tmp.insert(pii{nx, ny});
                        }else{
                            auto jt = tmp.find(pii{nx, ny});
                            if(jt != tmp.end()) tmp.erase(jt);
                        }                        
                    }
                }
            }
        }

        Candi.swap(tmp);
        if(Candi.empty()) break;
    } 
    cout << Black.size() << endl;
    return;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);	
    int nofkase = 1;
    while(nofkase--) work();
	return 0;
}